/*
 * 斐波那契数列 Fibonacci
 */

#include <stdio.h>

#define NUM 10

/* 迭代实现 */
void func_1()
{
	int i;
	int a[40];
	a[0] = 0;
	a[1] = 1;
	
	printf("迭代展示斐波那契数列:\n");
	printf("a[0] = [%d]\n", a[0]);
	printf("a[1] = [%d]\n", a[1]);
	for (i = 2; i < NUM; ++i)
	{
		a[i] = a[i-1] + a[i-2];
		printf("a[%d] = [%d]\n", i, a[i]);
	}
}

int Fbi(int i)
{
	if (i < 2)
		return i == 1 ? 1 : 0;
	return Fbi(i-1) + Fbi(i-2);
}

/* 递归实现 */
void func_2()
{
	int i;
	printf("递归展示斐波那契数列:\n");
	for (i = 0; i < NUM; ++i)
		printf("a[%d] = [%d]\n", i, Fbi(i));
}


int main(void)
{
	func_1();
	func_2();
	
	return 0;
}

